package com.hanshushi_jiekou;

import java.util.function.Supplier;

public class SupplierDemo {
    public static void main(String[] args) {
        String string = getString(() -> "ceshi");
        System.out.println(string);

        Integer i = getInteger(() -> 30);
        System.out.println(i);

        int[] arr = {10, 22, 56, 4, 11};
        int res = getMax(() -> {
            int max = arr[0];
            for (int j = 1; j < arr.length; j++) {
                if (arr[j] > max) {
                    max = arr[j];
                }
            }
            return max;
        });
        System.out.println(res);
    }

    // 获取数组最大值
    private static int getMax(Supplier<Integer> sup) {
        return sup.get();
    }

    // 返回一个整数数据
    private static Integer getInteger(Supplier<Integer> sup) {
        return sup.get();
    }

    // 定义一个方法，返回一个字符串数据
    private static String getString(Supplier<String> sup) {
        return sup.get();
    }
}
